package project.controller;

import project.entity.Student;
import project.service.StudentService;
import project.service.impl.StudentServiceImpl;
import project.utils.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/*
杨威
2021/9/11
17:56
*/
@WebServlet("/showAllStudentController")
public class ShowAllStudentController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pageIndex = req.getParameter("pageIndex");
        if(pageIndex==null){
            pageIndex="1";
        }
        System.out.println(pageIndex);
        Page page= new Page(Integer.valueOf(pageIndex));
        StudentService studentService=new StudentServiceImpl();
        List<Student> students = studentService.showAllStudentByPage(page);
        req.setAttribute("studentList",students);
        req.setAttribute("page",page);
        req.getRequestDispatcher("/showAllStudent.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
